<template>
	<view class="container">
		<view class="head-title">
			<view class="head-title-layer" @tap='onPersonInfo'>
				<image class="head_image_icon" src="/static/images/logo.png"></image>
				<view class="head-title-name">
					<view>{{userInfo.userName}}</view>
					<view>{{userInfo.mobile || userInfo.telephone || userInfo.areaCode}}</view>
				</view>
			</view>			
		</view>
		
		<view class="menu-root" v-for="(item,index) in menuData" :key="index" @tap="handleWay(item.link,index)">
			<view class="menu-item" hover-class="menu-hover">
				<view class="menu-left">
					<image class="menu-image" v-bind:src="item.imagsLeft"></image>
					<text>{{item.title}}</text>
				</view>
				<view v-if="item.id==4" class="menu-left">
					<text  v-if="number>0" class="number-hint" >{{number}}</text>
					
					<image class="menu-image margin-right-0" v-bind:src="menuRight.imagsRight"></image>
					
				</view>
				<view v-if="item.id!==4" class="menu-left">
					<text v-if="item.number" class="number-hint" >{{item.number}}</text>
					
					<image class="menu-image margin-right-0" v-bind:src="menuRight.imagsRight"></image>
					
				</view>
			</view>
			<view class="menu-line"></view>
		</view>
		<button class='btn' @tap="outlogin" >退出登录</button>
	</view>
</template>

<script>
	import apis from '../../api.js'
	import {
		mapState,
		mapMutations
	} from 'vuex' 

	export default {
		data() {
			return {
				number:0,
				menuRight:{
					imagsRight:'/static/images/right.png',
				},
				menuData : [{
				  imagsLeft: '/static/images/order.png',
				  title: '我的账单',
				  number:0,
				  link:'./bill-record/bill-record',
				  id:1
				}, 
				{
				  imagsLeft: '/static/images/product.png',
				  title: '已购产品',
				  number:0,
				  link:'./purchased-products/purchased-products',
				  id:2
				}, 
				{
				  imagsLeft: '/static/images/refresh.png',
				  title: '授权刷新',
				  number:0,
				  link:'./entitle-refresh/entitle-refresh',
				  id:3
				}, 
				{
				  imagsLeft: '/static/images/shopping_cart_nol.png',
				  title: '购物车',
				  number:0,
				  link:'../buycar/buycar',
				  id:4
				}, 
				{
				  imagsLeft: '/static/images/setting.png',
				  title: '设置',
				  number:0,
				  link:'./person-setting/person-setting',
				  id:5
				}, 
				{
				  imagsLeft: '/static/images/agentpay.png',
				  title: '绑定副卡',
				  number:0,
				  link:'./bindcard/bindcard',
				  id:6
				}]
			}
		},
		onLoad() {
		},
		onShow() {
			var that= this
			var shoppingCart = uni.getStorageSync('shoppingCart')
			that.number = shoppingCart ? (shoppingCart.length <= 0 ? "" : shoppingCart.length > 9?"9+":shoppingCart.length):""
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']), //对全局变量hasLogin进行监控
		},
		methods: {
			...mapMutations(['logout']), //对全局方法 login进行监控
			onPersonInfo(){
				uni.navigateTo({
					url:'./person-info/person-info',
				})
			},
			handleWay(url,index) {
						uni.navigateTo({
							url: url
						})						
			},
			outlogin(){
				this.logout()
				uni.clearStorage();
				 uni.reLaunch({
				 	url:'../login/login?Type=0'
				 })
			}
		}
	}
</script>

<style scoped>
	page{
		background-color: #F1F1F1;
	}
	//----head----
	.head-title{
		display: flex;
		justify-content: center;
		align-items: center;
		width: calc(100% - 40rpx);
		padding: 20rpx;
		margin-bottom: 20rpx;
		background-color: white;
	}
	.head-title-layer{
		width: 100%;
		height: 220rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: row;
		align-items:center;
		background: linear-gradient(to right,  rgb(0, 185, 239), rgba(0, 185, 239, 0.7));
	}
	.head_image_icon{
		width: 100rpx;
		height: 100rpx;
		margin: 20rpx;
	}
	.head-title-name{
		height: 100rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: space-between;
		color: white;
	}
	
	//---menu item
	.menu-root{		
		width: 100%;
		background-color: white;
	}
	.menu-item{
		width: calc(100% - 40rpx);
		height: 90rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 0rpx 20rpx 1rpx 20rpx;
	}
	.menu-left{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.menu-line{
	  width: 100%;
	  height: 1rpx;
	  background-color: #F1F1F1;
	}
	.menu-image{
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
	}
	.menu-hover{
		background-color: #e3e3e5;
	}
	.number-hint{
		height: 30rpx;
		width: 30rpx;
		border-radius: 15rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		text-align: center;
		color: white;
		background-color: red;
		font-size: 24rpx;
	}
	.margin-right-0{
		margin-right: 0rpx;
	}
	//-----
	.btn {
	  width: 90%;
	  height: 90rpx;
	  margin-top: 100rpx;
	  display: flex;
	  justify-content: center;
	  align-items: center;
	  border: 2rpx none #00b9ef;
	  border-radius: 10rpx;
	  color: white;
	  background-color: #00b9ef;
	}
</style>
